<?php
class mdl_member_limit extends ujn_model {
	// 达到count条件, 则返回true, 否则返回false
	function check($mid, $flag, $count) {
		return $count <= (int)$this->mc('limit_mid', 'votelimit')->get("{$mid}_{$flag}");
	}
	
	function getSurplus($mid, $flag, $count) {
		return tls_func::uint($count - (int)$this->mc('limit_mid', 'votelimit')->get("{$mid}_{$flag}"));
	}

	// 递增记录数, 默认当天有效, 12点后失效
	function increment($mid, $flag, $expire = 84600) {
		return $this->mc('limit_mid', 'votelimit')->increment("{$mid}_{$flag}", 1, $expire);
	}	
	
	protected function __construct() {
		parent::__construct();
	}

    /**
     * 单例模型
     * @return mdl_member_limit
     */
	static function getInstance() {
        return parent::getInstance(__CLASS__);
	}	
}